//
//  AuthServiceViewController.m
//  HaierGMS_APP
//
//  Created by 堂堂 on 16/10/10.
//  Copyright © 2016年 堂堂. All rights reserved.
//

#import "AuthServiceViewController.h"
#import "UIColor+Hex.h"
#import "MBProgressHUD+MJ.h"
#import "AuthViewController.h"
@interface AuthServiceViewController ()
@property NSInteger pos;
@property NSString *service_str;

@end

@implementation AuthServiceViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    _content.backgroundColor = [UIColor colorWithHexString:@"#f2f2f2"];
    [self initView1];
    
    _content1.tag = 1;
    _content2.tag = 2;
    _content3.tag = 3;
    
    [_content1 addTarget:self action:@selector(content_click:) forControlEvents:UIControlEventTouchUpInside];
    [_content2 addTarget:self action:@selector(content_click:) forControlEvents:UIControlEventTouchUpInside];
    [_content3 addTarget:self action:@selector(content_click:) forControlEvents:UIControlEventTouchUpInside];
    [_saveBtn setTitleColor:[UIColor colorWithHexString:@"#ff7e00"] forState:UIControlStateNormal];
    [_saveBtn addTarget:self action:@selector(save_click:) forControlEvents:UIControlEventTouchUpInside];
}


-(void)initView1{
    _content3.hidden = YES;
    _lab1.text = @"家居类";
    _lab2.text = @"卫浴类";
    _image1.hidden = YES;
    _image2.hidden = YES;
    _image3.hidden = YES;
    _saveBtn.hidden = YES;
}

-(void)initView2{
    _content3.hidden = NO;
    _lab1.text = @"配送";
    _lab2.text = @"安装";
    _lab3.text = @"维修";
    _image1.hidden = YES;
    _image2.hidden = YES;
    _image3.hidden = YES;
    _saveBtn.hidden = NO;
}

-(void)content_click:(UIView *)view{
    int tag = view.tag;
    if(_pos == 0){
        
        if (tag == 1) {
            _service_str = @"家居类-";
        }
        if (tag == 2) {
            _service_str = @"卫浴类-";
        }
        
        [self initView2];
        _pos = 1;
    }else{
        if (tag == 1) {
            if(_image1.hidden){
                _image1.hidden = NO;
            }else{
                _image1.hidden = YES;
            }
            
        }
        if (tag == 2) {
            if(_image2.hidden){
                _image2.hidden = NO;
            }else{
                _image2.hidden = YES;
            }
        }
        if (tag == 3) {
            if(_image3.hidden){
                _image3.hidden = NO;
            }else{
                _image3.hidden = YES;
            }
        }
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

-(void)save_click:(UIView *)view{
    if (_image1.hidden && _image2.hidden && _image3.hidden) {
        [MBProgressHUD showError:@"请选择服务类型"];
    }else{
        if (!_image1.hidden) {
            _service_str = [NSString stringWithFormat:@"%@%@,",_service_str,@"配送"];
        }
        if (!_image2.hidden) {
            _service_str = [NSString stringWithFormat:@"%@%@,",_service_str,@"安装"];
        }
        if (!_image3.hidden) {
            _service_str = [NSString stringWithFormat:@"%@%@,",_service_str,@"维修"];
        }
        _service_str = [_service_str substringToIndex:_service_str.length - 1];
        
        AuthViewController *auth = self.navigationController.viewControllers[self.navigationController.viewControllers.count - 2];
        auth.auth_type = _service_str;
        [self.navigationController popToViewController:auth animated:YES];
    }
}

- (IBAction)back_click:(id)sender {
    
    if(_pos == 1){
        [self initView1];
        _pos = 0;
    }else{
        [self.navigationController popViewControllerAnimated:YES];
  
    }
        
}
@end
